package moe.oil.email.controller;

import lombok.Setter;
import lombok.extern.log4j.Log4j2;
import moe.oil.api.databaseAPI.DatabaseAPI;
import moe.oil.dto.user.UserDTO;
import moe.oil.email.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * author: 紫月
 * Date: 2022/04/17 13:57
 * Description:
 *
 * @author - -
 */
@RestController
@RequestMapping("/email")
@CrossOrigin
@Setter(onMethod_ = @Autowired)
@Log4j2
public class EmailController {
    private EmailService emailService;
    private DatabaseAPI databaseAPI;


    @PostMapping("/send")
    public boolean send(@RequestBody UserDTO userDTO) {
        emailService.send(userDTO);
        return true;
    }

    @GetMapping("/validate/{token}")
    public String validate(@PathVariable("token") String token) {
        return emailService.verify(token);
    }

    @GetMapping("/db/{id}")
    public String test(@PathVariable Integer id) {
        return databaseAPI.test(id);
    }

    @GetMapping("/test/{value}")
    public String test(@PathVariable(value = "value", required = false) String value) {
        return value;
    }

}








